﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Threading;

namespace devtm.Documentation.CSharpModel
{

    public abstract class ListItem : ItemsSourceCache, INotifyPropertyChanged, ISearchTarget
    {
        // Fields
        private PropertyChangedEventHandler _PropertyChanged;

        // Events
        public event PropertyChangedEventHandler PropertyChanged
        {
            add
            {
                PropertyChangedEventHandler handler2;
                PropertyChangedEventHandler propertyChanged = this._PropertyChanged;
                do
                {
                    handler2 = propertyChanged;
                    PropertyChangedEventHandler handler3 = (PropertyChangedEventHandler)Delegate.Combine(handler2, value);
                    propertyChanged = Interlocked.CompareExchange<PropertyChangedEventHandler>(ref this._PropertyChanged, handler3, handler2);
                }
                while (propertyChanged != handler2);
            }
            remove
            {
                PropertyChangedEventHandler handler2;
                PropertyChangedEventHandler propertyChanged = this._PropertyChanged;
                do
                {
                    handler2 = propertyChanged;
                    PropertyChangedEventHandler handler3 = (PropertyChangedEventHandler)Delegate.Remove(handler2, value);
                    propertyChanged = Interlocked.CompareExchange<PropertyChangedEventHandler>(ref this._PropertyChanged, handler3, handler2);
                }
                while (propertyChanged != handler2);
            }
        }

        // Methods
        protected ListItem()
        {
        }

        public bool IsMatch(IEnumerable<string> searchTerms)
        {
            return ((this.Title != null) && searchTerms.Any<string>(term => (this.Title.IndexOf(term, StringComparison.InvariantCultureIgnoreCase) >= 0)));
        }

        protected void RaisePropertyChanged(string name)
        {
            PropertyChangedEventHandler propertyChanged = this._PropertyChanged;
            if (propertyChanged != null)
            {
                propertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }

        // Properties
        public abstract string Title { get; }
    }



}
